<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use Log;
use Exception;

class LogController extends Controller{

    /**
     * 查看laravel日志
     * @param $year
     * @param $month
     * @param $day
     * @return string
     */
    public function show_laravel_log($year, $month, $day) {
        $f_path = storage_path(sprintf('logs/laravel-%s-%s-%s.log', $year, $month, $day));
        if (file_exists($f_path)) {
            return '<div style="width:3000px">'.str_replace(array("\r\n", "\r", "\n"), "<br>", file_get_contents($f_path)).'</div>';
        } else {
            return 'not  exists';
        }
    }




    /**
     * 删除laravel日志
     * @param $year
     * @param $month
     * @param $day
     * @return string
     */
    public function del_laravel_log($year, $month, $day) {
        $f_path = storage_path(sprintf('logs/laravel-%s-%s-%s.log', $year, $month, $day));
        if (file_exists($f_path)) {
            unlink($f_path);
            return 'done!';
        } else {
            return 'not exists';
        }
    }


    /**
     * 查看wechat日志
     * @return string
     */
    public function show_wechat_log() {
        $f_path = storage_path(sprintf('logs/wechat.log'));
        if (file_exists($f_path)) {
            return '<div style="width:3000px">'.str_replace(array("\r\n", "\r", "\n"), "<br>", file_get_contents($f_path)).'</div>';
        } else {
            return 'not  exist';
        }
    }


    /**
     * 删除wechat日志
     * @param $year
     * @param $month
     * @param $day
     * @return string
     */
    public function del_wechat_log() {
        $f_path = storage_path(sprintf('logs/wechat.log'));
        if (file_exists($f_path)) {
            unlink($f_path);
            return 'done';
        } else {
            return 'not exists';
        }
    }


}
